package com.ma.pojo;

import com.ma.controller.doubleNodeController;

/**
 * 堆栈
 * @param <T>
 */
public class stackPlus<T>{
    private stack<Integer> stackData;
    private stack<Integer> stackMin;
    public stackPlus(){
        this.stackData=new stack<>();
        this.stackMin=new stack<>();
    }

    /**
     * 压栈
     * @param num
     */
    public void push(int num){
        if(this.stackMin==null){
            this.stackMin.push(num);
        }else if(num<this.getMin()){
            this.stackMin.push(num);
        }else {
            int newMin=this.stackMin.peek();
            this.stackMin.push(num);
        }
        this.stackData.push(num);

    }

    /**
     * 出栈
     * @return
     */
    public int pop(){
        if(this.stackMin==null){
            throw new RuntimeException("栈为空！");
        }
        this.stackMin.remove();
        return this.stackData.remove();
    }

    /**
     * 获取当前栈最小值
     * @return
     */
    private int getMin() {
        if(this.stackMin==null){
            throw new RuntimeException("栈为空！");
        }
        return this.stackMin.peek();

    }


}
